﻿
var requestUpdatePsdUrl = SystemLimitUrl + "/user/updatePsd";
var ajaxSaveCfgUrl = TriageUrl+'/Triage/modifyTriageConfigInfo';
$(function () {
    $('#mytab a:first').tab('show');
    getNurseConfig();// 获取支持的打印机设备
    $("#but_linkFenZhen,#btn-back,#btn-backs").click(function () {
        try { my_cefsharp.Set_PageKeyFlag_Cef("Patient.nurse"); } catch (err) { }
        window.location.href = "../index.html";
    });

    $("#but_linkPaiBan").click(function () {
        window.location.href = "../arrange/arrange_list.html";
    });

    $("#dept_name_index").html(unescape(getCookie("deptName")));
    $("#name_index").html(unescape(getCookie("name")));
    var pwdStatus = parseInt(unescape(getCookie("pwdStatus")));

    if (pwdStatus == 1 || pwdStatus == 2) {
        $("#span_oper").hide();
    } else {
        $("#span_oper").show();
    }

    $("#but_save").click(function () {
        var _userId = getCookie("userId");
        var _oldpwd = $("#txt_old_pwd").val();
        var _newpwd = $("#txt_new_pwd").val();
        var _agin_newpwd = $("#txt_agin_new_pwd").val();

        if (_oldpwd.trim() == "") {
            layer.alert("原密码不能为空", { icon: 2 });
            return;
        }
        if (_newpwd.trim() == "") {
            layer.alert("新密码不能为空", { icon: 2 });
            return;
        }

        if (_newpwd.trim().length < 1 || _newpwd.trim().length > 20) {
            layer.alert("密码长度1-20个字节", { icon: 2 });
            return;
        }

        if (_newpwd != _agin_newpwd) {
            layer.alert("两次输入的密码不一致!", { icon: 2 });
            return;
        }

        if (pattern.test(_newpwd)) {
            layer.alert("密码不能包含特殊字符.", { icon: 2 });
            return false;
        }

        $.ajax({
            url: requestUpdatePsdUrl,
            type: 'post',
            data: {
                userId: _userId,
                hospitalId: getLocalDeviceCookie("HOSPITAL_ID"),
                loginPwd: _oldpwd,
                newPwd: _newpwd
            },
            success: function (d) {
                if (JSON.parse(d).status == '0') {
                    RedirectByKey("Patient.nurse");
                } else {
                    layer.alert(JSON.parse(d).desc, { icon: 2 });
                }
            }
        });
    });
    try{
        var gender = localStorage.getItem('gender');
        var frag = '<option value="1" selected>男</option><option value="0">女</option>';
        if(gender==0){
            frag = '<option value="1" >男</option><option selected value="0">女</option>';
        }
        $('#sexDefault').html(frag);
    }catch (e) {

    }
});

/**
 *  获取打印机配置
 * **/
function getNurseConfig(){
    try{
        my_cefsharp.GetPrintDrivers(dealPrintDrivers);
    }catch (e) {

    }

}
/**
 *  获取选中的值
 * **/
function getCheckedNurseConfig() {
    try {
        my_cefsharp.Get_PrintDevice(dealResultPrintDevice);
    } catch (e) {

    }
}

// 处理打印机选中的值
function dealResultPrintDevice(str){
    $('input[name="printer"][value="'+str+'"]').prop('checked',true);
}

function dealPrintDrivers(str){
    var arr = JSON.parse(str) || [];
    var frag = '';
    for (var i =0,lens = arr.length;i<lens;i++){
        if(arr[i]){
            frag += '<label><input type="radio" value="'+arr[i]+'" name="printer">'+arr[i]+'</label>';
        }
    }
    $('#printer').html(frag);
    getCheckedNurseConfig();
}

function saveConfig() {
    var gender = $('#sexDefault').val();
    $.ajax({
        url: ajaxSaveCfgUrl,
        type: 'post',
        data: {
            triageId: unescape(getCookie("deviceId")),
            sexDefault: gender
        },
        success: function (d) {
            if (JSON.parse(d).status == '0') {
                localStorage.setItem('gender',gender);
                RedirectByKey("Patient.nurse");
            } else {
                layer.alert(JSON.parse(d).desc, { icon: 2 });
            }
        }
    });
}

/**
 * @description: 保存读卡器或者打印机
 * **/
function saveNurseConfig() {
    // 保存打印机
    var printer = $('input[name="printer"]:checked').val();
    try {
        my_cefsharp.Save_PrintDevice(printer);
    } catch (e) {
        console.log(printer);
    }
    getNurseConfig();
    layer.msg('保存成功');
}



